home *** CD-ROM | disk | FTP | other *** search
/ InterCD 1999 March / marchl_1999.iso / Site Building / Mallsurfer Shop / _SETUP.1 / cart_js.txt < prev    next >
Encoding:
Text File  |  1998-11-10  |  6.5 KB  |  238 lines

  1. <head>
  2.  
  3. <title>###SHOP_NAME### : ###SHOP_DESCRIPTION###</title>
  4.  
  5. <meta name=description content="###SHOP_NAME### : ###SHOP_DESCRIPTION###">
  6.  
  7. <meta name=keywords content="###SHOP_NAME### : ###SHOP_DESCRIPTION### : msrtcm : ms105">
  8.  
  9. </head>
  10.  
  11. <body background="images/###MENU_BGGRAPHIC###" bgcolor="###BG_COLOR###" text="###TEXT_COLOR###" link="###LINK_COLOR###" vlink="###VLINK_COLOR###" alink="###ALINK_COLOR###">
  12.  
  13.  
  14. <center>
  15.  
  16. <script language="JavaScript">
  17.  
  18. MaxCartItems = 15;
  19.  
  20. function getCookieVal (offset) {
  21.   var endstr = document.cookie.indexOf (";", offset);
  22.   if (endstr == -1)
  23.     endstr = document.cookie.length;
  24.   return unescape(document.cookie.substring(offset, endstr));
  25. }
  26.  
  27. function GetCookie (name) {
  28.   var arg = name + "=";
  29.   var alen = arg.length;
  30.   var clen = document.cookie.length;
  31.   var i = 0;
  32.   while (i < clen) {
  33.     var j = i + alen;
  34.        if (document.cookie.substring(i, j) == arg)
  35.      return getCookieVal (j);
  36.     i = document.cookie.indexOf(" ", i) + 1;
  37.     if (i == 0) break; 
  38.   }
  39.   return null;
  40. }
  41.  
  42. function SetCookie (name, value) {
  43.   var argv = SetCookie.arguments;
  44.   var argc = SetCookie.arguments.length;
  45.   var expires = (argc > 2) ? argv[2] : null;
  46.   var path = (argc > 3) ? argv[3] : null;
  47.   var domain = (argc > 4) ? argv[4] : null;
  48.   var secure = (argc > 5) ? argv[5] : false;
  49.   document.cookie = name + "=" + escape (value) +
  50.     ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  51.     ((path == null) ? "" : ("; path=" + path)) +
  52.     ((domain == null) ? "" : ("; domain=" + domain)) +
  53.     ((secure == true) ? "; secure" : "");
  54. }
  55.  
  56. function DeleteCookie (name) {
  57.   var exp = new Date();
  58.   exp.setTime (exp.getTime() - 1);  // This cookie is history
  59.   var cval = GetCookie (name);
  60.   if (cval != null)
  61.     document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
  62. }
  63.  
  64. function ShowCart() 
  65. {
  66.     totprice = 0;
  67.     itemlist = 0;
  68.  
  69.     document.writeln('<form>');
  70.     document.writeln('To change quantity, edit number then click anywhere on this frame<p>');
  71.     document.writeln('<table border=2 cellspacing=5 cellpadding=5>');
  72.     document.writeln('<tr><td align=center><b>###ID###</b></td><td align=center><b>###DESCRIPTION###</b></td><td align=center><b>###QTY###</b></td><td align=center><b>###PRICE_EACH###</b></td><td align=center><b>###PRICE_TOTAL###</b></td><td align=center><b>###ACTION###</b></td></tr>');
  73.  
  74.     for(NumItems = 0; NumItems<MaxCartItems; NumItems++)
  75.     {
  76.         CookieName = "Cart" +NumItems;
  77.         CookieValue = GetCookie(CookieName);
  78.  
  79.         if(CookieValue != null)
  80.         {
  81.             for(var i = 0;i <= CookieValue.length; i++)
  82.             {
  83.                 // using 0192,0193,0194,0195,0196
  84.                 if (CookieValue.substring(i,i+1) == '[') 
  85.                 {
  86.                     itemstart = i+1;
  87.                 } 
  88.                 else if (CookieValue.substring(i,i+1) == '└') 
  89.                 {
  90.                     ID = CookieValue.substring(itemstart, i);
  91.                     itemstart = i+1;
  92.                 } 
  93.                 else if (CookieValue.substring(i,i+1) == '┴') 
  94.                 {
  95.                     Sdesc = CookieValue.substring(itemstart, i);
  96.                     itemstart = i+1;
  97.                 }
  98.                 else if (CookieValue.substring(i,i+1) == '┬') 
  99.                 {
  100.                     Price = CookieValue.substring(itemstart, i);
  101.                     itemstart = i+1;
  102.                 }
  103.                 else if (CookieValue.substring(i,i+1) == '├') 
  104.                 {
  105.                     itemend = i;
  106.                     Qty = CookieValue.substring(itemstart, itemend);
  107.                     ItemTotal = 0;
  108.                     ItemTotal = (eval(Price*Qty));
  109.                     temptotal = ItemTotal * 100;
  110.                     totprice = totprice + ItemTotal;
  111.                     itemlist=itemlist+1;
  112.  
  113.                     FItemTotal = FloatFormat(ItemTotal,2);
  114. document.writeln('<tr><td>'+ID+'</td><td>'+Sdesc+'</td><td align=right><input method=post name=Qty'+NumItems+' type=text size=3 onChange=QtyChange('+NumItems+',Qty'+NumItems+'.value) value='+Qty+'></td><td align=right>'+Price+'</td><td align=right>'+FItemTotal+'</td><td><a href="javascript:RemoveItem('+NumItems+')">Remove</a></td></tr>');
  115.                 } 
  116.                 else if (CookieValue.substring(i,i+1) == '─') 
  117.                 {
  118.                     Weight = CookieValue.substring(itemstart, i);
  119.                     itemstart = i+1;
  120.                 }
  121.                 else if (CookieValue.substring(i,i+1) == ']') 
  122.                 {
  123.                     WeightUnit = CookieValue.substring(itemstart, i);
  124.                     itemstart = i+1;
  125.                 }
  126.             }
  127.         }
  128.     }
  129.  
  130.     Ftotprice = FloatFormat(totprice,2);
  131.     document.writeln('<tr><td colspan=4><b>Sub Total</b></td><td align=right>'+Ftotprice+'</td><td></td></tr>');
  132.     document.writeln('</table>');
  133.     document.writeln('</form>');
  134. }
  135.  
  136. function QtyChange(itemnum,Qty)
  137. {
  138.     CookieName = "Cart" +itemnum;
  139.     CookieValue = GetCookie(CookieName);
  140.  
  141.     for(var i = 0;i <= CookieValue.length; i++)
  142.     {
  143.         // using 0192,0193,0194,0195,0196
  144.         if (CookieValue.substring(i,i+1) == '[') 
  145.         {
  146.             itemstart = i+1;
  147.         } 
  148.         else if (CookieValue.substring(i,i+1) == '└') 
  149.         {
  150.             ID = CookieValue.substring(itemstart, i);
  151.             itemstart = i+1;
  152.         } 
  153.         else if (CookieValue.substring(i,i+1) == '┴') 
  154.         {
  155.             Sdesc = CookieValue.substring(itemstart, i);
  156.             itemstart = i+1;
  157.         }
  158.         else if (CookieValue.substring(i,i+1) == '┬') 
  159.         {
  160.             Price = CookieValue.substring(itemstart, i);
  161.             itemstart = i+1;
  162.         }
  163.         else if (CookieValue.substring(i,i+1) == '├') 
  164.         {
  165.             OldQty = CookieValue.substring(itemstart, itemend);
  166.             itemstart = i+1;
  167.         } 
  168.         else if (CookieValue.substring(i,i+1) == '─') 
  169.         {
  170.             Weight = CookieValue.substring(itemstart, i);
  171.             itemstart = i+1;
  172.         }
  173.         else if (CookieValue.substring(i,i+1) == ']') 
  174.         {
  175.             WeightUnit = CookieValue.substring(itemstart, i);
  176.             itemstart = i+1;
  177.         }
  178.     }
  179.  
  180.     NewCookieValue = "["+ID+"└"+Sdesc+"┴"+Price+"┬"+Qty+"├"+Weight+"─"+WeightUnit+"]";
  181.     if(Qty <= 0)
  182.         DeleteCookie(CookieName)
  183.     else
  184.         SetCookie(CookieName,NewCookieValue);
  185.  
  186.     self.location = "cart.htm";
  187. }
  188.  
  189. function RemoveItem(itemnum)
  190. {
  191.     CookieName = "Cart" +itemnum;
  192.     DeleteCookie(CookieName);
  193.     self.location = "cart.htm";
  194. }
  195.  
  196. function EmptyCart()
  197. {
  198.     if(confirm('###ARE_YOU_SURE_EMPTY_CART###'))
  199.     {
  200.         for(NumItems = 0; NumItems<MaxCartItems; NumItems++)
  201.         {
  202.             CookieName = "Cart" +NumItems;
  203.             DeleteCookie(CookieName);
  204.         }
  205.  
  206.         self.location = "cart.htm";
  207.     }
  208. }
  209.  
  210. function FloatFormat(expr,decplaces)
  211. {
  212.     var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces));
  213.     while(str.length <= decplaces)
  214.     {
  215.         str = "0" + str;
  216.     }
  217.  
  218.     var decpoint = str.length - decplaces;
  219.     return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
  220. }
  221.  
  222. function Dollarize(expr)
  223. {
  224.     return "$" + format(expr,2);
  225. }
  226.  
  227. </script>
  228.  
  229. <script language="JavaScript">
  230.     ShowCart();
  231. </script>
  232.  
  233. <form>
  234. <input type=button name=clear value="###EMPTY_SHOPPING_CART###" onClick="EmptyCart()">
  235. </form>
  236.  
  237. </center>
  238.